package tripService;

import java.util.List;

import com.jfinal.plugin.activerecord.Page;

import tripModel.Location;

public class LocationService {
	private static final int pageSize = 8;

	/*
	 * 鎸変富棰樺垎椤垫樉绀烘櫙鐐�
	 */
	public static final Page<Location> findLocationByTotal(Long tID, int pageNumber) {
		return Location.dao.paginate(pageNumber, 6, "select l.`lID`,l.`lName`,l.`lintro`,li.`liimgPath`",
				"from `location` l left join limg li on l.lID=li.lilID where l.lTID=? and li.liIsTop='1'", tID);
	}

	// 热门景点
	public static final Page<Location> showhot(int pageNumber) {
		return Location.dao.paginate(pageNumber, 8, "select lID,lName,lintro ", "from location order by lMoods desc");
	}

	public static final List<Location> showtop() {
		return Location.dao.find(
				"select l.lID,l.lName,li.liimgPath from `location` AS l left join `limg` as li ON l.lID=li.lilID WHERE li.liisTop='1' ORDER BY li.liCreateDate asc LIMIT 3");
	}

	public static final List<Location> findLocationByTop() {
		return Location.dao.find(
				"select l.lID,l.lName,li.liimgPath from `location` AS l left join `limg` as li ON l.lID=li.lilID WHERE li.liisTop='1' ORDER BY li.liCreateDate DESC LIMIT 6");
	}

	/*
	 * 鏄剧ず绗竴涓煄甯傛櫙鐐逛俊鎭�
	 */
	public static List<Location> findLocationByFirstProvince() {
		return Location.dao.find(
				"SELECT l.lID,l.lName,li.liimgPath FROM location l LEFT JOIN limg li ON li.liLID=l.lID WHERE lCID=110100 AND li.liisTop='1'");
	}

	public static final List<Location> findLocationByCreateDateToTop() {
		return Location.dao.find("select lID,lName,lintro from location order by lcreateDate desc limit 3");
	}

	/*
	 * 閫氳繃鍩庡競id鏌ヨ鏅偣
	 */
	public static final List<Location> findLocationByID(Long id) {
		return Location.dao.find(
				"SELECT l.lID,l.lName,li.liimgPath FROM location l LEFT JOIN limg li ON li.liLID=l.lID WHERE lCID=? AND li.liisTop='1'",
				id);
	}

	/*
	 * 閫氳繃鏅偣id鑾峰緱鏅偣淇℃伅
	 */
	public static final Location findLocationByLid(Long Lid) {
		return Location.dao.findByIdLoadColumns(Lid, "lID,lCID,lTID,lName,lintro,lContent,lMoods,lCreateDate");
	}

	/*
	 * 鑾峰緱鐑棬鏅偣
	 */
	public static final Page<Location> findLocationByMoods(int pageNumber) {

		return Location.dao.paginate(pageNumber, pageSize, "select lID,lName,lintro",
				"from location order by lMoods DESC");
	}
}
